package com.levi.utils.log;


import com.levi.utils.log.printer.AndroidLogcatPrinter;
import com.levi.utils.log.printer.LogFilePrinter;

import java.io.File;

import androidx.annotation.NonNull;

/**
 * Created by Levi on 2018/3/13.
 */

public class LogUtils {
    private static final String TAG = "LogUtils";

    private static boolean sDebug = false;

    public static boolean isDebug() {
        return sDebug;
    }

    public static void init(@NonNull LogConfig config) {
        LogUtils.sDebug = config.isDebug;
        if (!sDebug) {
            return;
        }
        Logger.addPrinter(new AndroidLogcatPrinter());
        if (config.mLogDir != null) {
            Logger.addPrinter(new LogFilePrinter(config.mLogDir));
        }
    }

    private LogUtils() {
        throw new AssertionError("Don't instance!");
    }

    @Deprecated
    public static void e(String tag, String msg, Throwable tr) {
        Logger.e(tag, msg, tr);
    }

    public static void e(String tag, String msg) {
        Logger.e(tag, msg);
    }

    public static void e(String tag, String msg, Object... args) {
        e(tag, null, msg, args);
    }

    public static void e(String tag, Throwable tr, String msg, Object... args) {
        Logger.e(tag, tr, msg, args);
    }

    public static void e(String msg) {
        e("", msg);
    }

    public static void e(Throwable tr) {
        e("", tr, "");
    }

    public static void e(String tag, Throwable tr) {
        e(tag, tr, "");
    }

    public static void d(String tag, String msg) {
        Logger.d(tag, msg);
    }

    public static void d(String msg) {
        d("", msg);
    }

    public static void d(String tag, String msg, Object... args) {
        d(tag, null, msg, args);
    }

    public static void d(String tag, Throwable tr, String msg, Object... args) {
        Logger.d(tag, tr, msg, args);
    }

    public static void i(Throwable tr) {
        i("", tr, "");
    }

    public static void i(String msg) {
        i("", msg);
    }

    public static void i(String tag, String msg) {
        Logger.i(tag, msg);
    }

    public static void i(String tag, String msg, Object... args) {
        i(tag, null, msg, args);
    }

    public static void i(String tag, Throwable tr, String msg, Object... args) {
        Logger.i(tag, tr, msg, args);
    }

    public static void v(String msg) {
        v("", msg);
    }

    public static void v(String tag, String msg, Object... args) {
        v(tag, null, msg, args);
    }

    public static void v(String tag, Throwable tr, String msg, Object... args) {
        Logger.v(tag, tr, msg, args);
    }

    public static void w(String tag, String msg, Object... args) {
        w(tag, null, msg, args);
    }

    public static void w(String tag, Throwable tr, String msg, Object... args) {
        Logger.w(tag, tr, msg, args);
    }

    public static void wtf(String tag, String msg, Object... args) {
        wtf(tag, null, msg, args);
    }

    public static void wtf(String tag, Throwable tr, String msg, Object... args) {
        Logger.wtf(tag, tr, msg, args);
    }

    public static class LogConfig {
        private File mLogDir;
        private boolean isDebug;

        public LogConfig setLogDir(File dir) {
            this.mLogDir = dir;
            return this;
        }

        public LogConfig setDebug(boolean debug) {
            isDebug = debug;
            return this;
        }
    }
}
